<?php $grid_size = Zend_Registry::get('grid-size')?>
<?php 
$url_tc = $this->url_tc;
$url_en = $this->url_en;
?>
<?php $key = 'header2_' . empty($this->loggedin_user->_id) .'_'. $grid_size.'_'.(!empty($this->current_language) ? (string) $this->current_language : '')?>
<?php if (true || ($output = $this->cacheOutput()->start($key)) === false):?>
    <section class="postAd">
        <p class="button em"><a href="<?php echo $this->geturl('post-an-ad','listing')?>"><?php echo $this->t('Post an Ad');?></a></p>
    </section>
    <section class="help">
        <p class="nav">
            <a class="country_hk" href="#">Hong Kong</a>
            <?php if ($this->current_language == 'en'):?>
                <a href="<?php echo $url_tc?>" class="language_chi_t">中文</a>
            <?php else:?>
                <a href="<?php echo $url_en?>" class="language_eng_t">English</a>
            <?php endif;?>
            <a href="http://blog.asiaclassified.com/"><?php echo $this->t('Blog');?></a>
            <a href="http://asiaclassified.zendesk.com/home"><?php echo $this->t('Help');?></a>
        </p>
    </section>
    <section class="search">
        <h1>
            <?php
            $ads_count = 0;
            $list = Model_Category::all(array('path'=>array('$size'=>1)));
            foreach($list as $cat) {
                $ads_count += $cat->listing_count;
            }
            /*
            $solr = Ac_Search::getClient();
            $query = '*:*';
            $additionalParameters['fq'] = ' +status:1 +type_obj_s:Model_Listing';
            $list = $solr->search($query, 0, 0, $additionalParameters);
            $ads_count = (int)$list->response->numFound;
            */
            //$ads_count = Model_Listing::all(array('sa' => Model_Listing::STATUS_PUBLISHED))->count();
            echo $this->t('Find <span><em>__1__</em></span> Ads for Property, Cars, Pets and more in HK', null, $ads_count);
            ?>
        </h1>
        <form action="<?php echo $this->geturl('regular','search')?>" method="get">
              <div class="text">
                <input type="text" name="keyword" value=""/>
              </div>
              <div class="select">
                <?php echo $this->getCategory()?>
              </div>
            <div class="button">
              <!--update: deleted class="button"-->
              <button type="submit"><?php echo $this->t('Search');?></button>
            </div>
          </form>
<?php /*
        <?php $car     = Model_Category::one(array('id' => 'mc55'))?>
        <?php $pets    = Model_Category::one(array('id' => 'mc56'))?>
        <?php $clothes = Model_Category::one(array('id' => 'mc51'))?>
        <p>
            <?php echo $this->t('Popular');?>: <a href="<?php echo $car->url()?>"><?php echo $this->t('Cars')?></a>
            <a href="<?php echo $pets->url()?>"><?php echo $this->t('Pets')?></a> <a href="<?php echo $clothes->url()?>"><?php echo $this->t('Clothes')?></a>
            </p>
 */?>
    </section>
    <section class="login">
        <?php if (empty($this->loggedin_user->_id)): ?>
            <div>
                <a href="<?php echo $this->geturl('login','user')?>" style="border:0;padding-left:0"><?php echo $this->t('Login')?></a>
                <a href="<?php echo $this->geturl('register','user')?>"><?php echo $this->t('Sign Up')?></a>
            </div>
        <?php else:?>
            <div>
                <a href="<?php echo $this->geturl('my-account','user')?>" style="border:0;padding-left:0" rel="<?php echo $this->loggedin_user->_id?>"><?php echo $this->t('My Account')?></a>
                <a href="<?php echo $this->geturl('logout','user')?>"><?php echo $this->t('Logout')?></a>
            </div>
        <?php endif; ?>
    </section>
    <?php $this->cacheOutput()->end(array('header2', $key))?>
    <!-- not cached: <?php echo $key?> -->
<?php else:?>
    <?php
        $keyword = '';
        if (Zend_Registry::isRegistered('search_keyword')) {
            $keyword = Zend_Registry::get('search_keyword');
        } elseif (!empty($_GET['keyword'])) {
            $keyword = $_GET['keyword'];
        }
        $output = str_replace(
                '<input type="text" name="keyword" value=""/>', 
                '<input type="text" name="keyword" value="'.$keyword.'"/>',
                $output);
        $output = preg_replace(
                '#<a href="(.*)" class="language_eng_t">English</a>#', 
                '<a href="'.$url_en.'" class="language_eng_t">English</a>',
                $output);
        $output = preg_replace(
                '#<a href="(.*)" class="language_chi_t">中文</a>#', 
                '<a href="'.$url_tc.'" class="language_chi_t">中文</a>',
                $output);
    ?>
    <?php echo $output?>
    <!-- cached: <?php echo $key?> -->
<?php endif;?>
